Skip to content

Conversation

@shsms
Copy link
Contributor

@shsms shsms commented Jun 16, 2025

It is similar to the LatestValueCache, but accepts an additional key-function as an argument, which takes each incoming message and returns a key for that message. The latest value received for each unique key gets cached and is available to look up on demand.

This also reverts the (unreleased) group-by-key extensions made to LatestValueCache, so that there is more time to finalise the API before making it stable.

Copilot AI review requested due to automatic review settings June 16, 2025 15:52
@shsms shsms requested a review from a team as a code owner June 16, 2025 15:52
@github-actions github-actions bot added part:docs Affects the documentation part:tests Affects the unit, integration and performance (benchmarks) tests part:experimental Affects the experimental package labels Jun 16, 2025
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR introduces an experimental cache – the GroupingLatestValueCache – which extends the existing caching functionality by grouping incoming messages by a key derived via a provided function. Key changes include:

  • Addition of a new implementation under src/frequenz/channels/experimental/_grouping_latest_value_cache.py.
  • Introduction of integration tests for the new cache in tests/test_grouping_latest_value_cache_integration.py.
  • Updates to release notes and removal of keyed tests from the LatestValueCache integration test.

Reviewed Changes

Copilot reviewed 6 out of 6 changed files in this pull request and generated no comments.

Show a summary per file
File Description
tests/test_latest_value_cache_integration.py Removed keyed tests to separate concerns with the experimental cache implementation.
tests/test_grouping_latest_value_cache_integration.py Added integration tests for validating the experimental grouping cache functionality.
src/frequenz/channels/experimental/_grouping_latest_value_cache.py Added a new cache class that groups received values by key and caches the latest value per key.
src/frequenz/channels/experimental/init.py Updated the module exports to include GroupingLatestValueCache.
src/frequenz/channels/_latest_value_cache.py Removed support for the key parameter to align with the new, experimental behavior.
RELEASE_NOTES.md Mentioned the new experimental GroupingLatestValueCache feature.
Comments suppressed due to low confidence (1)

src/frequenz/channels/experimental/_grouping_latest_value_cache.py:78

  • Consider adding a 'stop' method (similar to the one in LatestValueCache) to cancel the background task and ensure proper cleanup of resources.
self._task: asyncio.Task[None] = asyncio.create_task(

shsms added 2 commits June 16, 2025 17:55
…ceived (frequenz-floss#425)"

This reverts commit 6f24b25, reversing
changes made to 3edcb49.

Signed-off-by: Sahas Subramanian <[email protected]>
…s#424)"

This reverts commit 3edcb49, reversing
changes made to f7fb341.

Signed-off-by: Sahas Subramanian <[email protected]>
Copy link
Contributor

@ela-kotulska-frequenz ela-kotulska-frequenz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM :)

Comment on lines 128 to 134
def clear(self, key: HashableT) -> None:
"""Clear the latest value or the latest value for a specific key.

Args:
key: The key for which to clear the latest value.
"""
_ = self._latest_value_by_key.pop(key, None)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably not udpated documentation: "Clear the latest value for a specific key"

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

true, fixed.

shsms added 3 commits June 17, 2025 10:14
@shsms shsms force-pushed the GroupingLatestValueCache branch from 0fedafe to 7597e34 Compare June 17, 2025 08:14
@shsms shsms added this pull request to the merge queue Jun 17, 2025
Merged via the queue into frequenz-floss:v1.x.x with commit 41de546 Jun 17, 2025
5 checks passed
@shsms shsms deleted the GroupingLatestValueCache branch June 17, 2025 09:10
Copy link
Contributor

@llucax llucax left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was stating to write a lot of comments about using __contains__ instead of has_key, etc. but then probably we should just inherit from Mapping so we are required to follow the mapping interface, I think it is a perfect fit, this is basically a dict that is mutable/filled only externally by the passed receiver.

ValueError: If no value has been received yet.
"""
if key not in self._latest_value_by_key:
raise ValueError(f"No value received for key: {key!r}")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any reason why this is not a KeyError? 🤔

@shsms
Copy link
Contributor Author

shsms commented Jun 17, 2025

but then probably we should just inherit from Mapping so we are required to follow the mapping interface

That's a good idea, I'll try.

@llucax llucax added this to the v1.10.0 milestone Jun 25, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

part:docs Affects the documentation part:experimental Affects the experimental package part:tests Affects the unit, integration and performance (benchmarks) tests

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants